package dao

import (
	"mini-app/internal/dal"

	"golang.org/x/net/context"
)

type IGoodsSettingFilter interface {
	fmtFilter(ctx context.Context, tx dal.IGoodsSettingDo, q *dal.Query) dal.IGoodsSettingDo
}

var _ IGoodsSettingFilter = (*GoodsSettingFilter)(nil)

type GoodsSettingFilter struct {
	ID int64
	//Deleted *bool
	GoodsID string

	RobotID string
	//RobotIDs []string 删除的原因是，原来使用这个筛选来批量设置，但是误设了一批字段，所以改为一个一个设置
}

// 筛选器
func (p *GoodsSettingFilter) fmtFilter(ctx context.Context, tx dal.IGoodsSettingDo, q *dal.Query) dal.IGoodsSettingDo {
	//if p.ID != 0 {
	//	tx = tx.Where(q.GoodsSetting.ID.Eq(p.ID))
	//}

	if p.GoodsID != "" {
		tx = tx.Where(q.GoodsSetting.GoodsID.Eq(p.GoodsID))
	}

	if p.RobotID != "" {
		tx = tx.Where(q.GoodsSetting.RobotID.Eq(p.RobotID))
	}

	//if p.RobotIDs != nil && len(p.RobotIDs) > 0 {
	//	tx = tx.Where(q.GoodsSetting.RobotID.In(p.RobotIDs...))
	//}

	//if p.Deleted != nil {
	//	tx = tx.Where(q.GoodsSetting.Deleted.Is(*p.Deleted))
	//}
	return tx
}

type GoodsSettingListFilter struct {
	ID int64
	//Deleted *bool
	GoodsID string
	RobotID string
	Visible int
}

func (p *GoodsSettingListFilter) fmtFilter(ctx context.Context, tx dal.IGoodsSettingDo, q *dal.Query) dal.IGoodsSettingDo {
	//if p.ID != 0 {
	//	tx = tx.Where(q.GoodsSetting.ID.Eq(p.ID))
	//}

	if p.GoodsID != "" {
		tx = tx.Where(q.GoodsSetting.GoodsID.Eq(p.GoodsID))
	}

	if p.RobotID != "" {
		tx = tx.Where(q.GoodsSetting.RobotID.Eq(p.RobotID))
	}

	if p.Visible != 0 {
		tx = tx.Where(q.GoodsSetting.Visible.Eq(p.Visible))
	}
	//if p.Deleted != nil {
	//	tx = tx.Where(q.GoodsSetting.Deleted.Is(*p.Deleted))
	//} else {
	//	//默认只查询未被删除的
	//	tx = tx.Where(q.GoodsSetting.Deleted.Is(false))
	//}

	return tx
}

// 强类型 JOIN 查询筛选器接口
/*
type IGoodsSettingJoinFilter interface {
	fmtJoinFilter(ctx context.Context, main dal.IGoodsSettingDo, join dal.IJoinTableDo, q *dal.Query) dal.IGoodsSettingDo // 开发人员根据具体需求替换 IJoinTableDo
}


var _ IGoodsSettingJoinFilter = (*GoodsSettingJoinListFilter)(nil)

// 强类型 JOIN 查询列表筛选器
type GoodsSettingJoinListFilter struct {
	// 主表筛选条件
	ID       int64

	Deleted  *bool

}

// 强类型 JOIN 查询筛选器实现
func (p *GoodsSettingJoinListFilter) fmtJoinFilter(ctx context.Context, main dal.IGoodsSettingDo, join dal.IJoinTableDo, q *dal.Query) dal.IGoodsSettingDo {
	// 执行强类型 LEFT JOIN
	tx := main.LeftJoin(join, q.GoodsSetting.ID.EqCol(q.JoinTable.GoodsSettingID)) // 开发人员根据具体需求替换关联条件

	// 主表筛选条件
	if p.ID != 0 {
		tx = tx.Where(q.GoodsSetting.ID.Eq(p.ID))
	}


	// 删除标记筛选
	if p.Deleted != nil {
		tx = tx.Where(q.GoodsSetting.Deleted.Is(*p.Deleted))
	} else {
		// 默认只查询未被删除的记录
		tx = tx.Where(q.GoodsSetting.Deleted.Is(false))
	}

	return tx
}
*/
